<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
		<?php


		/*
		 * This script is used for parse  a xml file about Cis regulatory region
		 * it changes the contain of the tag "stable_gene_identifier" which is like "cluster...."
		 * by it's reference in the new db ("KH....").
		 * We use for that a csv file named "clustertogene.csv"
		 *
		 * the commented lines "/*" are usefull if you want to show the duplicates clusters.
		 */


		$doublon = array();
		$arrResult = array();
//		$arrLines = file('clustertogene.csv');
		$arrLines = file('your csv file.csv');
		foreach ($arrLines as $line) {
			$tmp = explode(';', $line);
			/*
			 * si tmp[1] c'est à dire le cluster.... existe déja, on le met à la suite
			 * de celui-ci, utilise ensuite le tableau doublon pour référencer uniquement les doublons
			 */
/*			if (array_key_exists(trim($tmp[1]), $arrResult)) {
				$arrResult[trim($tmp[1])] = $arrResult[trim($tmp[1])] . "/" . trim($tmp[0]);
				$doublon[trim($tmp[1])] = $arrResult[trim($tmp[1])];
			} else {
*/
				$arrResult[trim($tmp[1])] = trim($tmp[0]);
/*			}
*/
		}

		$dom = new DOMDocument();
		$dom->formatOutput = true;
		$dom->preserveWhiteSpace = false;
//		$dom->load('RegulatoryRegions_ciona_intestinalis.xml');
		$dom->load('your xml file.xml');
		$elts = $dom->getElementsByTagName('stable_gene_identifier');

$alreadyUsed = array();
		foreach ($elts as $elt) {
			
			$tmp = trim($elt->nodeValue);
/*
			if (!in_array($tmp, $alreadyUsed)) {
				if (array_key_exists($tmp, $doublon)) {
					print_r($tmp . " : " . $doublon[$tmp]);print_r("<br />");
					$alreadyUsed[] = $tmp;
				}
			}
*/
			$elt->nodeValue = utf8_encode($arrResult["$tmp"]);

		}

//		$dom->save('testintegration.xml');
		$dom->save('your xml destination.xml');
		?>
    </body>
</html>
